<?php
/**
 * 这是phpdoc的注释
 * Copyright (c) 2019. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */
require "/data/wwwroot/vendor/autoload.php";
class CoreDoc {
    /**
     * 描述
     * @params
     * @param $parameter
     * @param string $option
     */
    public function api($parameter, $option = "foo") {

    }

    protected function client_can_not_see() {
    }
}


function em_getallheaders()
{
    foreach ($_SERVER as $name => $value)
    {
        if (substr($name, 0, 5) == 'HTTP_')
        {
            $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
        }
    }
    return $headers;
}

use Zipkin\Endpoint;
use Zipkin\Propagation\TraceContext;
use Zipkin\Recording\Span;
use Zipkin\Samplers\BinarySampler;
use Zipkin\TracingBuilder;

use Zipkin\Timestamp;
use GuzzleHttp\Client;


exit;
$tracer = \modules\tracing\zipkin\ZipkinTracing::start('hello');


$tracer->span('memcache');

echo ' execute ';
sleep(2);


exit;

$headers = [];

/* Injects the context into the wire */
$injector = $tracing->getPropagation()->getInjector(new Map());
$injector($span->getContext(), $headers);

var_dump($headers);


/* Creates the span for getting the users list */
$childSpan = $tracer->newChild($span->getContext());
$childSpan->start();
$childSpan->setKind(Zipkin\Kind\CLIENT);
$childSpan->setName('users:get_list');
//
//
////$headers = [];
////
/////* Injects the context into the wire */
////$injector = $tracing->getPropagation()->getInjector(new Map());
////$injector($childSpan->getContext(), $headers);
////
////var_dump($headers);
////
////exit;
//
/* HTTP Request to the backend */
$httpClient = new Client();
$request = new \GuzzleHttp\Psr7\Request('POST', 'http://liyutong180220.top/backend.php', $headers);
$childSpan->annotate('request_started', Timestamp\now());
$response = $httpClient->send($request);
$childSpan->annotate('request_finished', Timestamp\now());
//
//echo $response->getBody()->getContents();
//
usleep(500 * rand(1, 20));
$childSpan->finish();




//$service = new Yar_Server(new CoreDoc());
//$service->handle();